dojo.provide("msos.common");
msos.common.xml="<?xml version=\"1.0\" encoding=\"utf-8\"?>"+"\n";
msos.common.doctype={xhtml_strict:"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">",xhtml_MP12:"<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.2//EN\" \"http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd\">",xhtml_trans:"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"};
for(var key in msos.common.doctype){
msos.common.doctype[key]+="\n"+"<html xmlns=\"http://www.w3.org/1999/xhtml\">"+"\n";
}
msos.common.content={xml:"<meta http-equiv=\"content-type\" content=\"application/xhtml+xml; charset=utf-8\" />"+"\n",xhtml:"<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />"+"\n"};
msos.common.browser_current=function(){
var _1=[];
if(!window.focus){
_1.push("window.focus");
}
if(!document.open){
_1.push("document.open");
}
if(!document.write){
_1.push("document.write");
}
if(!document.close){
_1.push("document.close");
}
if(!document.images){
_1.push("document.images");
}
if(!document.styleSheets){
_1.push("document.styleSheets");
}
if(_1.length==0){
console.debug("browser_current -> Browser is current");
return true;
}else{
console.debug("browser_current -> Browser does not support: "+_1.join(", ")+" -> for content type "+djConfig.msos_content);
if(djConfig.msos_content=="xml"&&window.focus&&document.images&&document.styleSheets){
return true;
}
}
console.warn("browser_current -> Browser is not current");
return false;
};
msos.common.browser_editable=function(){
if(!(document.designMode||document.body.contentEditable)){
return false;
}
if(typeof (document.execCommand)=="undefined"){
return false;
}
console.debug("browser_editable -> Browser supports content editing");
return true;
};
msos.common.get_active_css=function(){
var i=0,a,_4=dojo.query("link");
a=_4[i];
while(a){
if(a.getAttribute("rel").indexOf("style")!=-1&&a.getAttribute("title")&&!a.disabled){
return a.getAttribute("title");
}
a=_4[i++];
}
return null;
};
msos.common.open_popup_window=function(_5,_6,_7,_8,_9,_a,_b,_c,_d,_e,_f){
var _10="Popup window failed!";
var _11=null;
var _12={width:0,height:0};
var _13=_c||218;
var _14=_d||272;
var _15=_e||[];
var _16=_f||"";
var _17=function(){
return true;
};
var _18=false;
if(_13<100){
_13=100;
}
if(_14<100){
_14=100;
}
if(_15[0]){
console.debug(_15);
}
var _19="width="+_13+",height="+_14+",left=2,top=2,dependent=1,status=0,toolbar=0,menubar=0,"+"scrollbars=0,personalbar=0,resizable=0,location=0,directories=0,hotkeys=0";
for(var j=0;j<_15.length;j++){
var _1b=_15[j]+"=0";
var _1c=_15[j]+"=1";
var _1d=new RegExp(_1b,"i");
if(_1d.test(_19)){
_19=_19.replace(_1d,_1c);
}else{
_19=_19+","+_1c;
}
}
_11=window.open(_16,_6,_19,true)||null;
if(_11&&!_11.closed){
if(msos.common.var_is_null(_11.document)){
djConfig.msos_popups_blocked=true;
}
if(msos.common.var_is_null(_11.closed)){
djConfig.msos_popups_blocked=true;
}
}else{
djConfig.msos_popups_blocked=true;
}
if(djConfig.msos_popups_blocked){
_11=null;
console.warn("open_popup_window -> Popup window failed or blocked!");
}
if(_11){
var _1e="";
var _1f="";
var _20="";
var _21=djConfig.msos_doctype;
if(_5=="image"){
_1f="<img src=\""+_b+"\" alt=\""+_7+"\" />";
_20="<a href=\""+_b+"\"><b>"+_9+"</b></a>";
}else{
if(_5=="iframe"){
_1f="<iframe id=\"popup_iframe\" src=\""+_b+"\"></iframe>";
_20="<a href=\""+_b+"\"><b>"+_9+"</b></a>";
_21="xhtml_trans";
}else{
if(_5=="debug"){
_1f="<pre id=\"popup_debug_el\">"+_9+"</pre>";
_20="<a href=\""+_b+"\"><b>"+_b+"</b></a>";
}else{
if(_5=="div"){
_1f="Add content using 'popup_content' element and innerHTML";
_20="<a href=\""+_b+"\"><b>"+_9+"</b></a>";
}else{
if(_5=="url"){
return _11;
}else{
console.warn("open_popup_window - No window type specified!");
return null;
}
}
}
}
}
if(djConfig.msos_content=="xml"){
_1e=msos.common.xml;
}
_1e+=msos.common.doctype[_21];
_1e+="<head>\n";
_1e+=msos.common.content[djConfig.msos_content];
_1e+="<title>"+_7+"</title>\n";
_1e+=_a+"\n";
_1e+="</head>\n<body>\n";
_1e+="<div id='popup_title'>"+_8+"</div>\n";
_1e+="<div id='popup_content'>\n"+_1f+"</div>\n";
_1e+="<div id='popup_buttons'>\n"+_20+"</div>\n";
_1e+="</body>\n</html>";
_10="Popup window created -> "+_5;
_17=function(){
if(_11&&!_11.closed){
_11.close();
}
};
var _22=_11.document;
_22.open();
_22.write(_1e);
_22.close();
_11.focus();
if(_5=="debug"){
console.info(_10);
}else{
dojo.connect(window,"onfocus",null,_17);
if(djConfig.isDebug){
console.debug(_10);
var _23=_19.split(",");
_19=_23.join(", ");
console.info("Popup window parameters: "+_19);
_12=msos.common.getViewport(_11);
console.info("Actual window size: Width: "+_12.width+" Height: "+_12.height);
}
}
}
return _11;
};
msos.common.open_dialog_window=function(_24,url,_26,_27,_28,_29,_2a,_2b,_2c,_2d,_2e){
var _2f=_2e||[];
var _30={_main_obj:_24,_action:_29,_arguments:_2a,_required:_2b||null,_validate:_2c||null,_cancel:_2d||null};
var dlg=msos.common.open_popup_window("url",_26,"","","","","",_27,_28,_2f,url);
if(dlg){
dlg.dialog=_30;
}
window.pop_dialog=_30;
return dlg;
};
msos.common.init_popup=function(win){
var _33=win.document;
var _34=this;
this.popup_cancel=function(){
msos.common.popup_cancel(win);
};
this.init_fields=function(){
if(!win.dialog){
if(win.opener&&win.opener.pop_dialog){
win.dialog=win.opener.pop_dialog;
}
}
if(!win.dialog){
if(win.opener){
win.opener.console.warn("init_fields -> Failed: missing dialog object");
}
msos.common.popup_cancel(win);
return false;
}
var _35="Input Values:\n";
var _36=win.dialog._arguments||{};
for(var _37 in _36){
_35+=_37+" -> "+_36[_37]+"\n";
var _38=dojo.byId(_37,_33)||null;
if(_38){
var _39=_38.tagName.toLowerCase();
if(_39=="div"){
_38.innerHTML=_36[_37];
}else{
if(_39=="select"){
msos.common.set_select_menu(_38,_36[_37]);
}else{
_38.value=_36[_37];
}
}
}else{
_35+="Error: missing\ninput element? -> "+_37+"\n";
}
}
msos.common.debug_write(_35);
win.opener.console.debug("init_popup - init_fields -> Success!");
return true;
};
this.popup_action=function(){
var _3a="Raw data output:\n";
if(!win.dialog){
win.opener.console.warn("init_popup - popup_action -> Failed: missing dialog object");
msos.common.popup_cancel(win);
return false;
}
var _3b=new Object();
var _3c=win.dialog._arguments||{};
var _3d=win.dialog._required||{};
var _3e=win.dialog._validate||function(_3f,_40,_41){
_41[_40]=_3f.value||"";
};
for(var i in _3d){
var el=dojo.byId(i,_33)||null;
if(el&&!el.value){
alert(_3d[i]);
el.focus();
return false;
}
}
for(var _44 in _3c){
var el=dojo.byId(_44,_33)||null;
if(el){
_3e(el,_44,_3b);
_3a+=_44+" -> "+_3b[_44]+"\n";
}else{
win.opener.console.warn("init_popup - popup_action -> Setting popup action failed - field: "+_44);
msos.common.popup_cancel(win);
return false;
}
}
_3a+="Final Values:\n";
for(var _44 in _3c){
if(_3c[_44]==_3b[_44]){
_3b[_44]="";
}
_3a+=_44+" -> "+_3b[_44]+"\n";
}
msos.common.debug_write(_3a);
win.dialog._action(_3b);
return true;
};
};
msos.common.popup_cancel=function(_45){
var _46=null;
if(_45&&!_45.closed){
if(_45.dialog){
_46=_45.dialog._cancel||null;
}
if(_46){
_46();
}
_45.close();
_45=null;
return false;
}
return true;
};
msos.common.set_popup_position=function(_47,_48,_49){
var cs=dojo.getComputedStyle(_47);
var pos=cs.position;
var _4c=_48||_47;
if(pos!="absolute"){
_47.style.position="absolute";
}
var _4d=dojo._abs(_4c,true);
var _4e=_49.adj_left||0;
var _4f=_49.adj_top||0;
console.debug("  Param pos (rel): top -> "+_4f+", left -> "+_4e);
_4e=_4e+_4d.x;
_4f=_4f+_4d.y;
console.debug("  Input pos (abs): top -> "+_4d.y+", left -> "+_4d.x);
console.debug("Display pos (abs): top -> "+_4f+", left -> "+_4e);
_47.style.left=_4e+"px";
_47.style.top=_4f+"px";
};
msos.common.set_suppress_ie_objects=function(_50,_51,_52){
if(!document.all){
return;
}
for(var k=0;k<_51.length;k++){
var _54=document.getElementsByTagName(_51[k].toUpperCase());
var _55;
var _56;
var _57;
var _58;
for(var i=0;i<_54.length;i++){
var _5a=_54[i];
if(!_5a||!_5a.offsetParent){
continue;
}
var _5b=_5a,_55=0,_56=0,_57=_5b.offsetHeight,_58=_5b.offsetWidth;
while(_5b.tagName!="BODY"){
_55+=_5b.offsetLeft;
_56+=_5b.offsetTop;
_5b=_5b.offsetParent;
}
if(!((_50.offsetLeft+_50.offsetWidth)<=_55)&&!((_50.offsetTop+_50.offsetHeight)<=_56)&&!(_50.offsetTop>=(_56+_57))&&!(_50.offsetLeft>=(_55+_58))){
if(_5a.style.visibility==""||_5a.style.visibility=="visible"){
_52.push(_5a);
}
}
}
}
};
msos.common.switch_img_onmouseover=function(_5c,_5d,_5e){
if(!_5c||!_5c.src){
console.error("switch_img_onmouseover - No image specified!");
return;
}
var _5f=new RegExp(_5d);
var _60=_5c.src;
var _61=_60.replace(_5f,_5e);
dojo.connect(_5c,"onmouseover",null,function(evt){
_5c.src=_61;
var _63="\nMouseover URI -> \n"+_5c.src;
msos.common.event_debug(evt,_63);
});
dojo.connect(_5c,"onmouseout",null,function(evt){
_5c.src=_60;
var _65="\nMouseout URI -> \n"+_5c.src;
msos.common.event_debug(evt,_65);
});
if(_60==_61){
console.error("switch_img_onmouseover - Switch Image failed!");
}
};
msos.common.generate_img_button=function(_66){
this.button_mousedown=null;
this.button_mouseup=null;
this.button_onclick=null;
this.img_elm=null;
this.img_url=djConfig.msos_folder+"/images/";
this.img_name="missing.gif";
this.img_title="Click here!";
this.img_alt="Tool";
this.img_size="img_reg";
this.img_but_id="button";
this.but_style_on="button_on";
this.but_style_off="button_off";
this.but_style_hov="button_hover";
this.but_style_prs="button_press";
var _67=this;
this.set_state=function(id,_69){
var _6a=this[id];
var elm=this.element;
if(_6a!=_69){
switch(id){
case "enabled":
if(_69){
dojo.removeClass(elm,_67.but_style_off);
}else{
dojo.addClass(elm,_67.but_style_off);
}
break;
case "active":
if(_69){
dojo.addClass(elm,_67.but_style_prs);
}else{
dojo.removeClass(elm,_67.but_style_prs);
}
break;
}
this[id]=_69;
}
};
this.generate_img=function(){
var _6c=document.createElement("img");
var _6d=_67.img_url+_67.img_name;
_6c.src=_6d;
_6c.title=_67.img_title;
_6c.alt=_67.img_alt;
_6c.className=_67.img_size;
_6c.unselectable="on";
_6c.button={name:_67.img_but_id,element:_6c,enabled:true,active:false,text:false,cmd:_67.button_onclick,state:_67.set_state,context:null,tool:null};
return _6c;
};
this.img_button_append=function(){
var _6e=_67.generate_img();
dojo.connect(_6e,"onmouseover",null,function(evt){
if(_6e.button.enabled){
dojo.addClass(_6e,_67.but_style_hov);
}
var _70=msos.common.gen_input_debug(_6e,_6e.button,"mouse over");
msos.common.event_debug(evt,_70);
});
dojo.connect(_6e,"onmouseout",null,function(evt){
if(_6e.button.enabled){
dojo.removeClass(_6e,_67.but_style_hov);
dojo.removeClass(_6e,_67.but_style_on);
(_6e.button.active)&&dojo.addClass(_6e,_67.but_style_prs);
}
var _72=msos.common.gen_input_debug(_6e,_6e.button,"mouse out");
msos.common.event_debug(evt,_72);
});
dojo.connect(_6e,"onmousedown",null,function(evt){
evt.preventDefault();
evt.stopPropagation();
if(_6e.button.enabled){
dojo.addClass(_6e,_67.but_style_on);
dojo.removeClass(_6e,_67.but_style_prs);
if(_67.button_mousedown){
_67.button_mousedown();
}
}
var _74=msos.common.gen_input_debug(_6e,_6e.button,"mouse down");
msos.common.event_debug(evt,_74);
});
dojo.connect(_6e,"onmouseup",null,function(evt){
evt.preventDefault();
evt.stopPropagation();
if(_6e.button.enabled){
dojo.removeClass(_6e,_67.but_style_on);
dojo.removeClass(_6e,_67.but_style_hov);
if(_67.button_mouseup){
_67.button_mouseup();
}
}
var _76=msos.common.gen_input_debug(_6e,_6e.button,"mouse up");
msos.common.event_debug(evt,_76);
});
dojo.connect(_6e,"onclick",null,function(evt){
evt.preventDefault();
evt.stopPropagation();
if(_6e.button.enabled&&_6e.button.cmd){
_6e.button.cmd(_6e.button);
}
});
_67.img_elm=_6e;
_66.appendChild(_6e);
};
};
msos.common.getViewport=function(win){
var _79=win;
var _7a=win.document;
var w=0;
var h=0;
if(dojo.isMozilla){
w=_79.innerWidth;
h=_79.innerHeight;
}else{
if(!dojo.isOpera&&_79.innerWidth){
w=_79.innerWidth;
h=_79.innerHeight;
}else{
if(!dojo.isOpera&&dojo.exists(_7a,"documentElement.clientWidth")){
var w2=_7a.documentElement.clientWidth;
if(!w||w2&&w2<w){
w=w2;
}
h=_7a.documentElement.clientHeight;
}else{
if(_7a.body.clientWidth){
w=_7a.body.clientWidth;
h=_7a.body.clientHeight;
}
}
}
}
return {width:w,height:h};
};
msos.common.dec_to_hex=function(num){
var _7f=parseInt(num/16);
var _80=msos.common.dec_eq_hex(_7f);
var _81=num-(_7f*16);
return _80+""+msos.common.dec_eq_hex(_81);
};
msos.common.dec_eq_hex=function(num){
if(num<=9){
return num;
}
switch(num){
case 10:
return "A";
case 11:
return "B";
case 12:
return "C";
case 13:
return "D";
case 14:
return "E";
case 15:
return "F";
}
return 0;
};
msos.common.hex_to_dec=function(hex){
if(hex.length==6){
return msos.common.hex_to_dec(hex.substr(0,2))+" "+msos.common.hex_to_dec(hex.substr(2,2))+" "+msos.common.hex_to_dec(hex.substr(4,2));
}
var _84=parseInt(msos.common.hex_eq_dec(hex.substr(0,1)));
var _85=parseInt(msos.common.hex_eq_dec(hex.substr(1)));
return (_84*16)+_85;
};
msos.common.hex_eq_dec=function(num){
if(num<=9){
return num;
}
switch(num.toUpperCase()){
case "A":
return 10;
case "B":
return 11;
case "C":
return 12;
case "D":
return 13;
case "E":
return 14;
case "F":
return 15;
}
return 0;
};
msos.common.xml_innerhtml=function(elm,_88){
_88=msos.common.escape_xml(_88);
if(djConfig.debugAtAllCost){
console.debug("xml_innerhtml -> "+_88);
}
elm.innerHTML=_88;
};
msos.common.escape_xml=function(str){
str=str.replace(/&/gm,"&amp;").replace(/</gm,"&lt;").replace(/>/gm,"&gt;").replace(/"/gm,"&quot;");
return str;
};
msos.common.escape_string=function(str){
return ("\""+str.replace(/(["\\])/g,"\\$1")+"\"").replace(/[\f]/g,"\\f").replace(/[\b]/g,"\\b").replace(/[\n]/g,"\\n").replace(/[\t]/g,"\\t").replace(/[\r]/g,"\\r");
};
msos.common.var_is_null=function(_8b){
if(typeof (_8b)=="undefined"){
return true;
}
if(_8b==null){
return true;
}
return false;
};
msos.common.var_is_empty=function(_8c){
if(msos.common.var_is_null(_8c)){
return true;
}
if(_8c==""){
return true;
}
return false;
};
msos.common.gen_input_debug=function(elm,_8e,_8f){
var txt="\nGenerate button - "+_8f+"\nButton id -> "+_8e.name+"\nEnabled -> "+_8e.enabled+"\nActive -> "+_8e.active+"\nCurrent button class:\n"+elm.className;
return txt;
};
msos.common.remove_children=function(_91){
var _92=_91.childNodes.length||0;
var _93=0;
while(_91.hasChildNodes()){
_91.removeChild(_91.firstChild);
++_93;
}
console.debug("remove_children -> nodes removed: "+_93+" of "+_92);
};
msos.common.set_select_menu=function(_94,_95){
var _96=_94.options||[];
var _97=false;
if(!_95){
_96[0].selected=true;
_97=true;
}
for(var i in _96){
if(!_96[i]){
continue;
}
if(_96[i].value==_95){
_96[i].selected=true;
_97=true;
}
}
if(!_97){
var opt=document.createElement("option");
opt.value=_95;
opt.innerHTML=_95;
_94.appendChild(opt);
opt.selected=true;
}
};
msos.common.debug_window=null;
msos.common.debug_element=null;
if(window.opener){
msos.common.debug_window=window.opener.msos.common.debug_window||null;
msos.common.debug_element=window.opener.msos.common.debug_element||null;
}
msos.common.event_debug=function(evt,_9b){
if(!djConfig.msos_debug){
return;
}
var txt="no event";
var tag="na";
if(evt){
if(evt.type){
txt=evt.type;
}else{
txt="no type";
}
if(evt.target){
tag=evt.target.nodeName.toLowerCase();
if(evt.target.id){
tag+=" - "+evt.target.id;
}
}else{
tag="no target";
}
if(_9b){
tag+=_9b;
}
}
txt="Event = "+txt+"\nEvent target tag = "+tag;
msos.common.debug_write(txt);
if(djConfig.debugAtAllCost){
console.debug(evt);
}
};
msos.common.debug_write=function(_9e){
if(!djConfig.msos_debug){
return;
}
if(msos.common.debug_window&&msos.common.debug_element&&!msos.common.debug_window.closed){
if(dojo.isIE){
msos.common.debug_element.innerText=_9e;
}else{
msos.common.debug_element.innerHTML=_9e;
}
}
};
if(djConfig.msos_debug&&(!msos.common.debug_element||!msos.common.debug_window)){
msos.common.debug_window=msos.common.open_popup_window("debug","msos_debug_window","Debug Window","Javascript debug output","Debug output appears here!",djConfig.msos_style,"http://www.opensitemobile.com");
if(msos.common.debug_window){
var debug_element_set=function(){
msos.common.debug_element=dojo.byId("popup_debug_el",msos.common.debug_window.document);
};
setTimeout(debug_element_set,3000);
}
}

